package com.tt.service;

import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;
import com.tt.dao.FoodDaoImpl;
import com.tt.entity.Food;
import com.tt.entity.ListImg;




@Service
@Transactional
public class FoodserviceImpl {
	@Resource
    private FoodDaoImpl foodDaoImpl;
	
	
	//添加
	public boolean addFood(Food food) {
		
		int  addFood = foodDaoImpl.addFood(food);
		
		if(addFood>0){
			return true ;
		}else{
			return false;
		} 
	}
	
	//查询所有
	public List<Food> foodfoundAll(){
		return this.foodDaoImpl.foodfoundAll();
		
	}
	
	//删除
	 public void  deteleFood(Integer id){
		  this.foodDaoImpl.deteleFood(id);
	 }
	 
	 //修改
	 public  void  updateFood(Food food){
 
		 //判断图片是否为空，为空的话就调用图片修改updatephoto方法
		 //将商品原来的图片路径保存到该商品中
			if (food.getImg()==null||food.getImg().equals("")) {
				String listimg = foodDaoImpl.updatephoto(food.getId());
				food.setImg(listimg);
			}
			//若不为空,调用修改方法updateFood
			foodDaoImpl.updateFood(food);
			
	 }
	 
	 //id 单查
	 public Food showFood(Integer id){
		 return  this.foodDaoImpl.showFood(id);
	 }
	 
	 //foodsingle
	 public Food showFoodsingle(Integer id){
		 return  this.foodDaoImpl.showFoodsingle(id);
	 }
}
